Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read service specific endpoints from env/config #1014

Merged
merged 7 commits into from
Oct 10, 2023

Conversation

trivikr
Copy link
Contributor

@trivikr trivikr commented Oct 9, 2023

Issue

Internal JS-4281

Description

Reads service specific endpoints from environment or configuration

Testing

Test code:

import { DynamoDB, ListTablesCommand } from "@aws-sdk/client-dynamodb";
import { getEndpointFromInstructions } from "@smithy/middleware-endpoint";

const client = new DynamoDB();
const command = new ListTablesCommand({});
const endpoint = await getEndpointFromInstructions(
  command.input,
  ListTablesCommand,
  client.config
);

console.log({ endpoint: endpoint.url.href });

Copied the artifacts from PR into test code:

$ rm -rf node_modules/@smithy/middleware-endpoint

$ cp -R ../smithy-typescript/packages/middleware-endpoint node_modules/@smithy/middleware-endpoint

Configuration:

[default]
region = us-west-2

[profile config]
region = us-west-2
endpoint_url = http://config.custom.endpoint

[profile config-services]
region = us-west-2
services = config
endpoint_url = http://service.config.custom.endpoint
dynamodb =
    endpoint_url = http://invalid.dynamodb.config.custom.endpoint

[services config]
endpoint_url = http://invalid.config.custom.endpoint
dynamodb =
    endpoint_url = http://dynamodb.config.custom.endpoint

Client configuration

The highest preference if one provided during client creation

Code:

const client = new DynamoDB({ endpoint: "http://custom.endpoint" });

Output:

$ node endpoint.mjs
{ endpoint: 'http://custom.endpoint/' }

$ AWS_ENDPOINT_URL=http://env.custom.endpoint \
AWS_ENDPOINT_URL_DYNAMODB=http://dynamodb.env.custom.endpoint \
node endpoint.mjs 
{ endpoint: 'http://custom.endpoint/' }

$ AWS_PROFILE=config \
node endpoint.mjs
{ endpoint: 'http://custom.endpoint/' }

$ AWS_PROFILE=config-services \
node endpoint.mjs
{ endpoint: 'http://custom.endpoint/' }

AWS_ENDPOINT_URL_DYNAMODB

Populates endpoint from AWS_ENDPOINT_URL_DYNAMODB is set.

$ node endpoint.mjs
{ endpoint: 'https://dynamodb.us-west-2.amazonaws.com/' }

$ AWS_ENDPOINT_URL=http://env.custom.endpoint \
AWS_ENDPOINT_URL_DYNAMODB=http://dynamodb.env.custom.endpoint \
node endpoint.mjs 
{ endpoint: 'http://dynamodb.env.custom.endpoint/' }

$ AWS_ENDPOINT_URL_DYNAMODB=http://dynamodb.env.custom.endpoint \
AWS_PROFILE=config \
node endpoint.mjs 
{ endpoint: 'http://dynamodb.env.custom.endpoint/' }

$ AWS_ENDPOINT_URL_DYNAMODB=http://dynamodb.env.custom.endpoint \
AWS_PROFILE=config-services \
node endpoint.mjs 
{ endpoint: 'http://dynamodb.env.custom.endpoint/' }

AWS_ENDPOINT_URL

Populates endpoint from AWS_ENDPOINT_URL is set.

$ node endpoint.mjs                                                                               
{ endpoint: 'https://dynamodb.us-west-2.amazonaws.com/' }

$ AWS_ENDPOINT_URL=http://env.custom.endpoint \
node endpoint.mjs
{ endpoint: 'http://env.custom.endpoint/' }

$ AWS_ENDPOINT_URL=http://env.custom.endpoint \
AWS_PROFILE=config \
node endpoint.mjs
{ endpoint: 'http://env.custom.endpoint/' }

$ AWS_ENDPOINT_URL=http://env.custom.endpoint \
AWS_PROFILE=config-services \
node endpoint.mjs
{ endpoint: 'http://env.custom.endpoint/' }

config dynamodb.endpoint_url

$ AWS_PROFILE=config-services \
node endpoint.mjs
{ endpoint: 'http://dynamodb.config.custom.endpoint/' }

config endpoint_url

$ AWS_PROFILE=config \         
node endpoint.mjs
{ endpoint: 'http://config.custom.endpoint/' }

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr marked this pull request as ready for review October 9, 2023 20:38
@trivikr trivikr requested review from a team as code owners October 9, 2023 20:38
Copy link
Contributor

@syall syall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding @internal to every export make sense? I don't think customers should use these directly.

@trivikr
Copy link
Contributor Author

trivikr commented Oct 10, 2023

Would adding @internal to every export make sense?

None of the utilities added in this PR are exported at top level. We don't need to add @internal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants